package com.czl.module_storehouse.mvp.presenter;

import com.czl.base.data.bean.tengyun.LocatListBean;
import com.czl.base.data.bean.tengyun.ProductBean;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_base.mvp.presenter.BasePresenter;
import com.czl.module_base.observer.AbsHandleSubscriber;
import com.czl.module_storehouse.bean.EditInventoryInfoBean;
import com.czl.module_storehouse.bean.InventoryBean;
import com.czl.module_storehouse.bean.InventoryInfoBean;
import com.czl.module_storehouse.bean.InventoryProductShiftBean;
import com.czl.module_storehouse.bean.InventoryProductStorageBean;
import com.czl.module_storehouse.bean.InventoryRoomBean;
import com.czl.module_storehouse.bean.RoomListBean;
import com.czl.module_storehouse.mvp.model.InventoryModel;
import com.czl.module_storehouse.mvp.view.InventoryView;

/**
 * @author by xubin,
 * @date on 2022/2/10.
 * PS: Not easy to write code, please indicate.
 */
public class InventoryPresenter extends BasePresenter<InventoryModel, InventoryView> {

    public static final String TAG_INVENTORY_SORT_INFO = "inventory_sort_info";
    public static final String TAG_INVENTORY_SHIFT = "inventory_shift";
    public static final String TAG_INVENTORY_ROOM_INFO = "inventory_room_info";
    public static final String TAG_INVENTORY_PRODUCT = "inventory_product";
    public static final String TAG_INVENTORY_EDIT_INFO = "inventory_edit_info";
    public static final String TAG_INVENTORY_ADD_INFO = "inventory_add_info";

    public void addInventoryInfo(InventoryInfoBean bean) {

        doSubscribe2(mModel.addInventoryInfo(bean), new AbsHandleSubscriber<HttpResponse<InventoryInfoBean>>() {
            @Override
            public void onSuccess(HttpResponse<InventoryInfoBean> response) {
                response.setRequestTag(TAG_INVENTORY_ADD_INFO);
                mView.showHttpResponse(response);
            }
        });
    }

    public void getNeedInventorySortInfo(boolean showLoading, boolean showDialog, int inventoryId, String roomId, String storehouseLocatId,
                                         EditInventoryInfoBean bean) {

        doSubscribe(mModel.getNeedInventorySortInfo(inventoryId, roomId, storehouseLocatId,
                bean), new AbsHandleSubscriber<HttpResponse<ListBean<LocatListBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<LocatListBean>> listBeanHttpResponse) {
                listBeanHttpResponse.setRequestTag(TAG_INVENTORY_SORT_INFO);
                mView.showHttpResponse(listBeanHttpResponse);
            }
        }, showLoading, showDialog, "加载中");
    }

    public void editInventoryInfo(EditInventoryInfoBean bean) {

        doSubscribe2(mModel.editInventoryInfo(bean), new AbsHandleSubscriber<HttpResponse<InventoryBean>>() {
            @Override
            public void onSuccess(HttpResponse<InventoryBean> httpResponse) {
                httpResponse.setRequestTag(TAG_INVENTORY_EDIT_INFO);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    /**
     * 单品移位
     *
     * @param bean
     */
    public void inventoryProductShift(InventoryProductShiftBean bean) {
        doSubscribe3(mModel.inventoryProductShift(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_INVENTORY_SHIFT);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    /**
     * 盘盈
     *
     * @param bean
     */
    public void inventoryProductStorage(InventoryProductStorageBean bean) {

        doSubscribe(mModel.inventoryProductStorage(bean), new AbsHandleSubscriber<HttpResponse<ListBean<ProductBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<ProductBean>> httpResponse) {
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void getInventoryRoomInfo(int inventoryId) {

        doSubscribe(mModel.getInventoryRoomInfo(inventoryId), new AbsHandleSubscriber<HttpResponse<ListBean<RoomListBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<RoomListBean>> httpResponse) {
                httpResponse.setRequestTag(TAG_INVENTORY_ROOM_INFO);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void getInventoryRoomList(int inventoryId) {

        doSubscribe3(mModel.getInventoryRoomList(inventoryId), new AbsHandleSubscriber<InventoryRoomBean>() {
            @Override
            public void onSuccess(InventoryRoomBean inventoryRoomBean) {
                mView.showData(inventoryRoomBean);
            }
        });
    }

    public void productInventory(ProductBean bean) {
        doSubscribe2(mModel.productInventory(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_INVENTORY_PRODUCT);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void getNeedDealtInvenList(boolean refresh) {
        resetPageNo(refresh);
        doSubscribe(mModel.getNeedDealtInvenList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<InventoryBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<InventoryBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void getDealtInvenList(boolean refresh) {
        resetPageNo(refresh);
        doSubscribe(mModel.getDealtInvenList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<InventoryBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<InventoryBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }
}
